//
//  ViewController.swift
//  JWQRCodeManager
//
//  Created by linjw on 01/12/2023.
//  Copyright (c) 2023 linjw. All rights reserved.
//

import UIKit
import JWQRCodeManager
import SnapKit
class ViewController: UIViewController {

    /// 扫码管理类
    lazy var manager: JWQRCodeManager = JWQRCodeManager()

    /// 扫描框
    lazy var scanAnimationView: JWQRCodeScanAnimationView = {
        let it = JWQRCodeScanAnimationView()
        return it
    }()

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        setupInit()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupInit()
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()

        configDatas()

    }

    func setupInit() {

    }

    func setupUI() {

        view.backgroundColor = .black
        if !((TARGET_IPHONE_SIMULATOR == 1 && TARGET_OS_IPHONE == 1)) {
            manager.configPreView(view)
        }

        view.addSubview(scanAnimationView)
        scanAnimationView.snp.makeConstraints {
            $0.centerX.equalToSuperview()
            $0.centerY.equalToSuperview()
            $0.size.equalTo(CGSize(width: 254, height: 254))
        }

    }

    func configDatas() {

//        manager.resultAction = { [weak self] text -> () in
//            debugPrint("\(text)")
//        }
        if !(TARGET_IPHONE_SIMULATOR == 1 && TARGET_OS_IPHONE == 1) {
//            manager.rx.rxReaultAction().map { [weak self] text in
//
//                self?.manager.stopScan()
//                self?.scanAnimationView.stopAnimation()
//
//            }.subscribe().disposed(by: rx.disposeBag)

            manager.startScan()
            scanAnimationView.startAnimation()
        } else {
            scanAnimationView.startAnimation()
            debugPrint("只有真机，才能扫描哦")
        }


    }
}

